// pages/chat/cityGroup/index.js
var basePage = require('../../../common/BasePage')
var baseList = require('../../../common/BaseList')
var QQMapWX = require('../../../utils/qqmap-wx-jssdk')
var keys = new QQMapWX({
    key: 'XKBBZ-DJULP-WSFD5-VPXP5-2IHCQ-2EF72'
});
Page({
    behaviors: [basePage, baseList],
    /**
     * 页面的初始数据
     */
    data: {
        city_code: null,
        reqUrl: '/home/chat/qrcode',
        showImg: false,
        imgUrl: ""
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.getAddress()
    },
    onPreviewImage(){

    },
    getAddress() {
        var that = this
        wx.getLocation({
            type: 'gcj02',
            success: function (res) {
                console.log("getLocation", res)
                var lat = res.latitude;
                var lng = res.longitude;
                //地图逆解析
                keys.reverseGeocoder({
                    location: {
                        latitude: lat,
                        longitude: lng
                    },
                    success: function (res) {
                        //获取详细地址
                        console.log("详细地址", res.result)
                        var city_code = res.result.ad_info.city_code
                        var result = city_code.substr(city_code.length - 6, city_code.length)

                        that.setData({
                            city_code: result
                        })
                        that.data.reqData.city_code = result
                        that.req_items()
                    },
                    fail: err => {
                        console.log("错误", err)
                        wx.showToast({
                            title: '定位失败',
                            icon: "none"
                        })
                    }
                })
            },
            fail: err => {
                console.log("错误", err)
                wx.showToast({
                    title: '定位失败',
                    icon: "none"
                })
            }
        })
    },
    init_val(val, index, arr) {
        val.thumb = this.get_thumb(val.photo);
    },
    onImg(e) {
        var item = e.currentTarget.dataset.item
        this.setData({
            showImg: true,
            imgUrl: item.thumb
        })
    },
    onClose() {
        this.setData({
            showImg: false
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },
})